

import excel "C:\Users\jrichman\Box Sync\2018 State Elections Paper\United States regional election data.xlsx", sheet("ChamberLevel") firstrow clear

import excel "C:\Users\Jesse\Box Sync\2018 State Elections Paper\Data\MeluskyRichman regional election data.xlsx", sheet("ChamberLevel") firstrow clear


generate PCIpctChange = (ST2018Q3-ST2017Q1)/ST2017Q1

generate RepublicanPostPortionPCT = RepublicanPostPortion*100
generate RepublicanPriorPortionPCT = RepublicanPriorPortion*100
generate StrictID = 0
replace StrictID = 1 if VoterID > 2
replace StrictID = 0 if VoterID < 4
generate PhotoID = 0
replace PhotoID = 1 if VoterID == 2
replace PhotoID = 1 if VoterID == 4
generate RepublicanControlLevel = 0
replace RepublicanControlLevel = 1 if LegCntlCoded == 1 
replace RepublicanControlLevel = RepublicanControlLevel+1 if GovPrtyCoded == 1


// correlations

correlate RepublicanPostPortionPCT RepublicanPriorPortionPCT Trumppct TrumpNetApprovalNovember2018

correlate RepublicanPostPortionPCT RepublicanPriorPortionPCT Trumppct TrumpApprovalChangeElection PercentofRepublicanswhoRetired termlimits PctRepChamberMembersTermed UE6monthchangetrend RepublicanControlLevel republicanportionoftwopartycampa RepublicanDistrictingPlan2010 Latino VoterID



//for help file on eststo command http://repec.org/bocode/e/estout/esttab.html
//Trump prior only
eststo: regress RepublicanPostPortionPCT Trumppct, vce(cluster postal)

//Trump only
eststo: regress RepublicanPostPortionPCT Trumppct TrumpApprovalChangeElection TrumpMidtermRallies, vce(cluster postal)

regress RepublicanPostPortionPCT Trumppct TrumpNetApprovalNovember2018 TrumpMidtermRallies, vce(cluster postal)

//Trump and lagged only
eststo: regress RepublicanPostPortionPCT RepublicanPriorPortionPCT Trumppct TrumpApprovalChangeElection TrumpMidtermRallies, vce(cluster postal)

//Leaving out retiremement variables and interactions
eststo: regress RepublicanPostPortionPCT RepublicanPriorPortionPCT Trumppct TrumpApprovalChangeElection c.UE6monthchangetrend i.RepublicanControlLevel republicanportionoftwopartycampa RepublicanDistrictingPlan2010 VoterID Latino TrumpMidtermRallies, vce(cluster postal)

//Term Limits and VoterID
eststo: regress RepublicanPostPortionPCT RepublicanPriorPortionPCT Trumppct TrumpApprovalChangeElection termlimits PctRepChamberMembersTermed c.UE6monthchangetrend i.RepublicanControlLevel republicanportionoftwopartycampa RepublicanDistrictingPlan2010 Latino VoterID TrumpMidtermRallies, vce(cluster postal)

// no interactions
eststo: regress RepublicanPostPortionPCT RepublicanPriorPortionPCT Trumppct TrumpApprovalChangeElection PercentofRepublicanswhoRetired termlimits PctRepChamberMembersTermed c.UE6monthchangetrend i.RepublicanControlLevel republicanportionoftwopartycampa RepublicanDistrictingPlan2010 Latino VoterID  TrumpMidtermRallies, vce(cluster postal)

// with interactions
eststo: regress RepublicanPostPortionPCT RepublicanPriorPortionPCT  TrumpApprovalChangeElection PercentofRepublicanswhoRetired termlimits PctRepChamberMembersTermed c.UE6monthchangetrend##i.RepublicanControlLevel republicanportionoftwopartycampa RepublicanDistrictingPlan2010 c.Latino##c.Trumppct VoterID TrumpMidtermRallies, vce(cluster postal)

margins, dydx(UE6monthchangetrend) at(RepublicanControlLevel=(0 1 2)) vsquish

margins, dydx(Latino) at(Trumppct=(30 (2) 68)) vsquish
marginsplot, graphregion(color(white)) bgcolor(white) recastci(rarea) recast(line) ci1opts(color(gs14) fintensity(100)) xdimension(Trumppct) xlabel(30 "30%" 50 "50%" 68 "68%") nolabels ytitle(Marginal Effect of Latino Percentage) xtitle(Trump 2016 Election Percentage) title(Figure 2. Marginal Effect of Latino Percentage on Republican Seat Share) 



esttab using tableA1b.rtf, star(+ 0.10 * 0.05) se ar2 onecell


eststo clear



// voter turnout analyses
regress turnout RepublicanPriorPortionPCT  TrumpApprovalChangeElection PercentofRepublicanswhoRetired termlimits PctRepChamberMembersTermed c.UE6monthchangetrend##i.RepublicanControlLevel republicanportionoftwopartycampa RepublicanDistrictingPlan2010 c.Latino##c.Trumppct VoterID, vce(cluster postal)

regress turnout  VoterID TrumpMidtermRallies, vce(cluster postal)

